﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Samurai.Infrastructure;

namespace Samurai.Client.DataContexts
{
    public class ShowByGenreCommand : ICommand
    {
        private readonly ObservableCollection<Movie> _movies;

        public ShowByGenreCommand(ObservableCollection<Movie> movies)
        {
            _movies = movies;
        }

        public void Execute(object parameter)
        {
            if (parameter != null)
            {

                _movies.Clear();

                var moviesByGenre = 
                    parameter.Equals("All") ? 
                    DAL.Manager.Instance.GetValidMovies() :
                    DAL.Manager.Instance.GetMoviesByGenre(parameter.ToString());

                foreach (var movie in moviesByGenre)
                {
                    _movies.Add(movie);
                }
            }
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;
    }
}
